JQuery

How to check checkbox is checked and unchecked in jquery ?

How to check checkbox is checked and unchecked in jquery ?, someone asked me to explain?

The jQuery prop() method is used to know the status of checkboxes which specifies its checked or unchecked status.


Do not confuse with "checked" attribute. The "checked" attribute only define the initial state of the checkbox, and not the current state.


<script type="text/javascript">
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
if($(this).prop("checked") == true){
alert("Checkbox is checked.");
}
else if($(this).prop("checked") == false){
alert("Checkbox is unchecked.");
}
});
});
</script>

Post your comments / questions